﻿using System.ComponentModel.Composition;
using NColony.Client.Wpf.ViewModels;
using NColony.Client.Wpf.ViewModels.Contracts;
using NColony.Dependencies;
using NColony.Dependencies.Contracts;
using NColony.Syndication.Receiver;
using NColony.Syndication.Receiver.Contracts;
using System.Reflection;

namespace NColony.Client.Wpf
{
    public static class DependencyManagerFactory
    {
        private static IDependencyManager dependencyManager;
        private static object dependencyManagerSyncLock = new object();

        [Export(typeof(IDependencyManager))]
        public static IDependencyManager DependencyManager
        {
            get
            {
                if (dependencyManager == null)
                {
                    lock (dependencyManagerSyncLock)
                    {
                        if (dependencyManager == null)
                        {
                            dependencyManager = new DefaultDependencyManager(
                                typeof(DependencyManagerFactory).Assembly,
                                typeof(IDependencyManager).Assembly,
                                typeof(DefaultDependencyManager).Assembly,
                                typeof(IMainWindowViewModel).Assembly,
                                typeof(MainWindowViewModel).Assembly,
                                typeof(ISyndicationReader<>).Assembly,
                                typeof(RssFeedReader).Assembly);
                        }
                    }
                }

                return dependencyManager;
            }
        }
    }
}
